<%@page pageEncoding="utf-8" contentType="text/html; charset=utf-8" %>
<%@ include file="/admin/include/init_admin.jsp" %>
<%@ page import="com.welfare.admin.call.*" %>
<%

	out.clear();
	out = pageContext.pushBody(); 
	
	
	String excelTitle = "상담통계";
	
	response.setHeader("Content-Disposition","attachment;filename="+java.net.URLEncoder.encode(excelTitle, "utf-8")+"_"+StringUtil.today()+".xls");
	response.setHeader("Content-Description","JSP Generated Data");



	HashList code305	= CommonUtil.getCodeList("305");	//분류1
	HashList code306	= CommonUtil.getCodeList("306");	//분류2
	
	//대분류별 소분류 갯수를 구한다.
	for (int i = 0; i < code305.size(); i++) {
		String counsel_kind = StringUtil.nvl(code305.get("code",i));
		int kind2 = 0; 
		for (int j = 0; j < code306.size(); j++) {
			if (counsel_kind.equals(code306.get("code_desc",j))) {
				kind2++;
			}
		}
		code305.put("code_num1", i, String.valueOf(kind2));
	}
	
	
	HashList code310	= CommonUtil.getCodeList("310");	//통계구분
	
	HashBox box = new HashBox(request);

	String s_from_dt		= StringUtil.nvl(request.getParameter("s_from_dt"), TODAY.substring(0,6)+"01");
	String s_to_dt			= StringUtil.nvl(request.getParameter("s_to_dt"), TODAY);
	String s_dong_code		= StringUtil.nvl(request.getParameter("s_dong_code"));
	String s_counsel_kind	= StringUtil.nvl(request.getParameter("s_counsel_kind"), "1");
	String s_group_col		= StringUtil.nvl(request.getParameter("s_group_col"), "counsel_path");


	HashMap infos = new HashMap();
	infos.put("from_dt",		s_from_dt);
	infos.put("to_dt",			s_to_dt);
	infos.put("dong_code",		s_dong_code);
	infos.put("counsel_kind", 	s_counsel_kind);
	infos.put("group_col", 		s_group_col);
	infos.put("code305",		code305);	//대분류
	infos.put("code306",    	code306);	//소분류

	CallDAO dao 	= new CallDAO();
	HashList list 	= dao.selectCounselAnalysis(infos);

	if ("1".equals(s_counsel_kind)) {

		list.setHeader("group_col", 	"구분",		MetaData.ALIGN_CENTER);
		list.setHeader("sum", 			"합계",		MetaData.ALIGN_RIGHT);
		for (int i = 0; i < code305.size(); i++) {
			list.setHeader("sum_"+code305.get("code",i), code305.get("code_name",i), MetaData.ALIGN_RIGHT);
		}
	}
	else {

		list.setHeaderGroup("group_col", 	"구분",		2, 1);
		list.setHeaderGroup("sum", 			"합계",		2, 1);
		for (int i = 0; i < code305.size(); i++) {
			list.setHeaderGroup("sum_"+code305.get("code",i), code305.get("code_name",i), 1, code305.getInt("code_num1",i));
		}

		list.setHeader("group_col", 	"",		MetaData.ALIGN_CENTER);
		list.setHeader("sum", 			"",		MetaData.ALIGN_RIGHT);
		for (int i = 0; i < code306.size(); i++) {
			list.setHeader("sum_"+code306.get("code",i), code306.get("code_name",i), MetaData.ALIGN_RIGHT);
		}
	}
	
	
	
	list.writeToExcel(response, excelTitle);
%>
